﻿using System;
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class _ThreadCuttingDieRoundShape3
    {
        public static void ThreadCuttingDieRoundShape3(Dictionary<string, Object> data)//细柄丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double scale = 2; //放大系数

            double oal = Convert.ToDouble(data["oal"]);
            double d = Convert.ToDouble(data["bd"]);
            double dc = Convert.ToDouble(data["td"]);
            var hand = "3";
            try
            {
                hand = data["hand"].ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine("[hand] not found");
            }

            if (hand.Equals("3"))
            {
                double g = 3;

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = fun.Polar(v1, (90 + 90 / g) * pi / 180, dc / 2);
                Vector2 v3 = fun.Polar(v1, (90 - 90 / g) * pi / 180, dc / 2);
                Vector2 v4 = new Vector2(v1.X, v1.Y + dc / 2 + (d / 2 - dc / 2) / 5.5);
                Vector2 v5 = fun.rotatePoint_Changed(v4, v2, -20);
                Vector2 v6 = fun.rotatePoint_Changed(v4, v3, 20);
                Vector2 v7 = fun.rotatePoint_Changed(v1, v2, -120);
                Vector2 v8 = fun.rotatePoint_Changed(v1, v3, -120);
                Vector2 v9 = fun.rotatePoint_Changed(v1, v4, -120);
                Vector2 v10 = fun.rotatePoint_Changed(v1, v7, -120);
                Vector2 v11 = fun.rotatePoint_Changed(v1, v8, -120);
                Vector2 v12 = fun.rotatePoint_Changed(v1, v9, -120);
                Vector2 v13 = fun.rotatePoint_Changed(v1, v5, -120);
                Vector2 v14 = fun.rotatePoint_Changed(v1, v6, -120);
                Vector2 v15 = fun.rotatePoint_Changed(v1, v13, -120);
                Vector2 v16 = fun.rotatePoint_Changed(v1, v14, -120);
                Vector2 a1 = new Vector2(v1.X - d / 2, v1.Y);
                Vector2 a2 = new Vector2(v1.X + d / 2, v1.Y);
                Vector2 a3 = new Vector2(v1.X - d / 2 - 2, v1.Y);
                Vector2 a4 = new Vector2(v1.X + d / 2 + 2, v1.Y);
                Vector2 a5 = new Vector2(v1.X, v1.Y + d / 2 + 2);
                Vector2 a6 = new Vector2(v1.X, v1.Y - d / 2 - 2);
                Vector2 a11 = new Vector2(v1.X - dc / 2, v1.Y);
                Vector2 a12 = new Vector2(v1.X + dc / 2, v1.Y);


                //侧视图
                Vector2 v17 = new Vector2(v1.X + d, v1.Y + d / 2);
                Vector2 v18 = new Vector2(v17.X, v17.Y - d);
                Vector2 v19 = new Vector2(v18.X + oal, v18.Y);
                Vector2 v20 = new Vector2(v19.X, v17.Y);
                Vector2 a7 = new Vector2(v17.X - 2, v1.Y);
                Vector2 a8 = new Vector2(v19.X + 2, v1.Y);
                Vector2 a9 = new Vector2(v17.X + oal / 2, v1.Y + d / 2 + 2);
                Vector2 a10 = new Vector2(v17.X + oal / 2, v1.Y - d / 2 - 2);

                //六边形
                Vector2 a13 = new Vector2(v1.X, v1.Y + d / 2 / Math.Cos(30 * pi / 180));
                Vector2 a14 = fun.rotatePoint_Changed(v1, a13, -60);
                Vector2 a15 = fun.rotatePoint_Changed(v1, a14, -60);
                Vector2 a16 = fun.rotatePoint_Changed(v1, a15, -60);
                Vector2 a17 = fun.rotatePoint_Changed(v1, a16, -60);
                Vector2 a18 = fun.rotatePoint_Changed(v1, a17, -60);


                fun.drawcircle(dxf, v1, d / 2, 0.1, contour);

                Arc arc1 = fun.DrawArc(v3, v4, v2);
                fun.drawBArc(dxf, arc1, 0.1, contour);

                Arc arc2 = fun.DrawArc(v8, v9, v7);
                fun.drawBArc(dxf, arc2, 0.1, contour);

                Arc arc3 = fun.DrawArc(v11, v12, v10);
                fun.drawBArc(dxf, arc3, 0.1, contour);

                Arc arc4 = fun.DrawArc(v7, v1, v3);
                fun.drawBArc(dxf, arc4, 0.1, contour);

                Arc arc5 = fun.DrawArc(v10, v1, v8);
                fun.drawBArc(dxf, arc5, 0.1, contour);

                Arc arc6 = fun.DrawArc(v2, v1, v11);
                fun.drawBArc(dxf, arc6, 0.1, contour);

                Arc arc7 = fun.DrawArc(v13, v1, v6);
                fun.drawBArc(dxf, arc7, 0.1, contour);

                Arc arc8 = fun.DrawArc(v15, v1, v14);
                fun.drawBArc(dxf, arc8, 0.1, contour);

                Arc arc9 = fun.DrawArc(v5, v1, v16);
                fun.drawBArc(dxf, arc9, 0.1, contour);

                LwPolyline line1 = new LwPolyline();
                line1.Vertexes.Add(new LwPolylineVertex(v17));
                line1.Vertexes.Add(new LwPolylineVertex(v18));
                line1.Vertexes.Add(new LwPolylineVertex(v19));
                line1.Vertexes.Add(new LwPolylineVertex(v20));
                line1.Vertexes.Add(new LwPolylineVertex(v17));
                fun.PolyFill(dxf, line1, 0.1, contour);

                Line line2 = new Line(a3, a4);
                line2.Layer = centre;
                line2.Linetype = Linetype.DashDot;
                line2.LinetypeScale = 3;
                dxf.AddEntity(line2);

                Line line3 = new Line(a5, a6);
                line3.Layer = centre;
                line3.Linetype = Linetype.DashDot;
                line3.LinetypeScale = 3;
                dxf.AddEntity(line3);

                Line line4 = new Line(a7, a8);
                line4.Layer = centre;
                line4.Linetype = Linetype.DashDot;
                line4.LinetypeScale = 3;
                dxf.AddEntity(line4);

                Line line5 = new Line(a9, a10);
                line5.Layer = centre;
                line5.Linetype = Linetype.DashDot;
                line5.LinetypeScale = 3;
                dxf.AddEntity(line5);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                line6.Vertexes.Add(new LwPolylineVertex(a14));
                line6.Vertexes.Add(new LwPolylineVertex(a15));
                line6.Vertexes.Add(new LwPolylineVertex(a16));
                line6.Vertexes.Add(new LwPolylineVertex(a17));
                line6.Vertexes.Add(new LwPolylineVertex(a18));
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                fun.PolyFill(dxf, line6, 0.1, contour);

                //标注

                double height = 2;
                double arrowsize = 2;
                double exline = 2;


                fun.dimrot1(dxf, a1, a2, 0, d / 2 + d / 4, 1, height, arrowsize, exline, "D=" + d, "", "");

                fun.dimrot1(dxf, v17, v20, 0, d / 4, 1, height, arrowsize, exline, "T=" + oal, "", "");

                fun.dimrot1(dxf, a11, a12, 180, d / 2 + d / 4, 1, height, arrowsize, exline, "TD=" + dc, "", "");

            }

            if (hand.Equals("4"))
            {
                double g = 4;

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = fun.Polar(v1, (90 + 90 / g) * pi / 180, dc / 2);
                Vector2 v3 = fun.Polar(v1, (90 - 90 / g) * pi / 180, dc / 2);
                Vector2 v4 = new Vector2(v1.X, v1.Y + dc / 2 + ((d - 5.4) / 2 - dc / 2) / 5.5);
                Vector2 v5 = fun.rotatePoint_Changed(v4, v2, -20);
                Vector2 v6 = fun.rotatePoint_Changed(v4, v3, 20);
                Vector2 v7 = fun.rotatePoint_Changed(v1, v2, -90);
                Vector2 v8 = fun.rotatePoint_Changed(v1, v3, -90);
                Vector2 v9 = fun.rotatePoint_Changed(v1, v4, -90);
                Vector2 v10 = fun.rotatePoint_Changed(v1, v7, -90);
                Vector2 v11 = fun.rotatePoint_Changed(v1, v8, -90);
                Vector2 v12 = fun.rotatePoint_Changed(v1, v9, -90);
                Vector2 v13 = fun.rotatePoint_Changed(v1, v10, -90);
                Vector2 v14 = fun.rotatePoint_Changed(v1, v11, -90);
                Vector2 v15 = fun.rotatePoint_Changed(v1, v12, -90);
                Vector2 v16 = fun.rotatePoint_Changed(v1, v5, -90);
                Vector2 v17 = fun.rotatePoint_Changed(v1, v6, -90);
                Vector2 v18 = fun.rotatePoint_Changed(v1, v16, -90);
                Vector2 v19 = fun.rotatePoint_Changed(v1, v17, -90);
                Vector2 v20 = fun.rotatePoint_Changed(v1, v18, -90);
                Vector2 v21 = fun.rotatePoint_Changed(v1, v19, -90);
                Vector2 a1 = new Vector2(v1.X - d / 2, v1.Y);
                Vector2 a2 = new Vector2(v1.X + d / 2, v1.Y);
                Vector2 a3 = new Vector2(v1.X - d / 2 - 2, v1.Y);
                Vector2 a4 = new Vector2(v1.X + d / 2 + 2, v1.Y);
                Vector2 a5 = new Vector2(v1.X, v1.Y + d / 2 + 2);
                Vector2 a6 = new Vector2(v1.X, v1.Y - d / 2 - 2);
                Vector2 a11 = new Vector2(v1.X - dc / 2, v1.Y);
                Vector2 a12 = new Vector2(v1.X + dc / 2, v1.Y);

                //侧视图
                Vector2 v22 = new Vector2(v1.X + d, v1.Y + d / 2);
                Vector2 v23 = new Vector2(v22.X, v22.Y - d);
                Vector2 v24 = new Vector2(v23.X + oal, v23.Y);
                Vector2 v25 = new Vector2(v24.X, v22.Y);
                Vector2 a7 = new Vector2(v22.X - 2, v1.Y);
                Vector2 a8 = new Vector2(v24.X + 2, v1.Y);
                Vector2 a9 = new Vector2(v22.X + oal / 2, v1.Y + d / 2 + 2);
                Vector2 a10 = new Vector2(v22.X + oal / 2, v1.Y - d / 2 - 2);

                //六边形
                Vector2 a13 = new Vector2(v1.X, v1.Y + d / 2 / Math.Cos(30 * pi / 180));
                Vector2 a14 = fun.rotatePoint_Changed(v1, a13, -60);
                Vector2 a15 = fun.rotatePoint_Changed(v1, a14, -60);
                Vector2 a16 = fun.rotatePoint_Changed(v1, a15, -60);
                Vector2 a17 = fun.rotatePoint_Changed(v1, a16, -60);
                Vector2 a18 = fun.rotatePoint_Changed(v1, a17, -60);




                fun.drawcircle(dxf, v1, d / 2, 0.1, contour);

                Arc arc1 = fun.DrawArc(v3, v4, v2);
                fun.drawBArc(dxf, arc1, 0.1, contour);

                Arc arc2 = fun.DrawArc(v8, v9, v7);
                fun.drawBArc(dxf, arc2, 0.1, contour);

                Arc arc3 = fun.DrawArc(v11, v12, v10);
                fun.drawBArc(dxf, arc3, 0.1, contour);

                Arc arc4 = fun.DrawArc(v14, v15, v13);
                fun.drawBArc(dxf, arc4, 0.1, contour);

                Arc arc7 = fun.DrawArc(v7, v1, v3);
                fun.drawBArc(dxf, arc7, 0.1, contour);

                Arc arc8 = fun.DrawArc(v10, v1, v8);
                fun.drawBArc(dxf, arc8, 0.1, contour);

                Arc arc9 = fun.DrawArc(v13, v1, v11);
                fun.drawBArc(dxf, arc9, 0.1, contour);

                Arc arc10 = fun.DrawArc(v2, v1, v14);
                fun.drawBArc(dxf, arc10, 0.1, contour);

                Arc arc11 = fun.DrawArc(v16, v1, v6);
                fun.drawBArc(dxf, arc11, 0.1, contour);

                Arc arc12 = fun.DrawArc(v18, v1, v17);
                fun.drawBArc(dxf, arc12, 0.1, contour);

                Arc arc13 = fun.DrawArc(v20, v1, v19);
                fun.drawBArc(dxf, arc13, 0.1, contour);

                Arc arc14 = fun.DrawArc(v5, v1, v21);
                fun.drawBArc(dxf, arc14, 0.1, contour);

                LwPolyline line1 = new LwPolyline();
                line1.Vertexes.Add(new LwPolylineVertex(v22));
                line1.Vertexes.Add(new LwPolylineVertex(v23));
                line1.Vertexes.Add(new LwPolylineVertex(v24));
                line1.Vertexes.Add(new LwPolylineVertex(v25));
                line1.Vertexes.Add(new LwPolylineVertex(v22));
                fun.PolyFill(dxf, line1, 0.1, contour);

                Line line2 = new Line(a3, a4);
                line2.Layer = centre;
                line2.Linetype = Linetype.DashDot;
                line2.LinetypeScale = 3;
                dxf.AddEntity(line2);

                Line line3 = new Line(a5, a6);
                line3.Layer = centre;
                line3.Linetype = Linetype.DashDot;
                line3.LinetypeScale = 3;
                dxf.AddEntity(line3);

                Line line4 = new Line(a7, a8);
                line4.Layer = centre;
                line4.Linetype = Linetype.DashDot;
                line4.LinetypeScale = 3;
                dxf.AddEntity(line4);

                Line line5 = new Line(a9, a10);
                line5.Layer = centre;
                line5.Linetype = Linetype.DashDot;
                line5.LinetypeScale = 3;
                dxf.AddEntity(line5);


                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                line6.Vertexes.Add(new LwPolylineVertex(a14));
                line6.Vertexes.Add(new LwPolylineVertex(a15));
                line6.Vertexes.Add(new LwPolylineVertex(a16));
                line6.Vertexes.Add(new LwPolylineVertex(a17));
                line6.Vertexes.Add(new LwPolylineVertex(a18));
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                fun.PolyFill(dxf, line6, 0.1, contour);

                //标注

                double height = 2;
                double arrowsize = 2;
                double exline = 2;


                fun.dimrot1(dxf, a1, a2, 0, d / 2 + d / 4, 1, height, arrowsize, exline, "D=" + d, "", "");

                fun.dimrot1(dxf, v22, v25, 0, d / 4, 1, height, arrowsize, exline, "T=" + oal, "", "");

                fun.dimrot1(dxf, a11, a12, 180, d / 2 + d / 4, 1, height, arrowsize, exline, "TD=" + dc, "", "");

            }

            if (hand.Equals("5"))
            {
                double g = 5;

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = fun.Polar(v1, (90 + 90 / g) * pi / 180, dc / 2);
                Vector2 v3 = fun.Polar(v1, (90 - 90 / g) * pi / 180, dc / 2);
                Vector2 v4 = new Vector2(v1.X, v1.Y + dc / 2 + ((d - 5.4) / 2 - dc / 2) / 5);
                Vector2 v5 = fun.rotatePoint_Changed(v4, v2, -20);
                Vector2 v6 = fun.rotatePoint_Changed(v4, v3, 20);
                Vector2 v7 = fun.rotatePoint_Changed(v1, v2, -72);
                Vector2 v8 = fun.rotatePoint_Changed(v1, v3, -72);
                Vector2 v9 = fun.rotatePoint_Changed(v1, v4, -72);
                Vector2 v10 = fun.rotatePoint_Changed(v1, v7, -72);
                Vector2 v11 = fun.rotatePoint_Changed(v1, v8, -72);
                Vector2 v12 = fun.rotatePoint_Changed(v1, v9, -72);
                Vector2 v13 = fun.rotatePoint_Changed(v1, v10, -72);
                Vector2 v14 = fun.rotatePoint_Changed(v1, v11, -72);
                Vector2 v15 = fun.rotatePoint_Changed(v1, v12, -72);
                Vector2 v16 = fun.rotatePoint_Changed(v1, v13, -72);
                Vector2 v17 = fun.rotatePoint_Changed(v1, v14, -72);
                Vector2 v18 = fun.rotatePoint_Changed(v1, v15, -72);
                Vector2 v19 = fun.rotatePoint_Changed(v1, v5, -72);
                Vector2 v20 = fun.rotatePoint_Changed(v1, v6, -72);
                Vector2 v21 = fun.rotatePoint_Changed(v1, v19, -72);
                Vector2 v22 = fun.rotatePoint_Changed(v1, v20, -72);
                Vector2 v23 = fun.rotatePoint_Changed(v1, v21, -72);
                Vector2 v24 = fun.rotatePoint_Changed(v1, v22, -72);
                Vector2 v25 = fun.rotatePoint_Changed(v1, v23, -72);
                Vector2 v26 = fun.rotatePoint_Changed(v1, v24, -72);
                Vector2 a1 = new Vector2(v1.X - d / 2, v1.Y);
                Vector2 a2 = new Vector2(v1.X + d / 2, v1.Y);
                Vector2 a3 = new Vector2(v1.X - d / 2 - 2, v1.Y);
                Vector2 a4 = new Vector2(v1.X + d / 2 + 2, v1.Y);
                Vector2 a5 = new Vector2(v1.X, v1.Y + d / 2 + 2);
                Vector2 a6 = new Vector2(v1.X, v1.Y - d / 2 - 2);
                Vector2 a11 = new Vector2(v1.X - dc / 2, v1.Y);
                Vector2 a12 = new Vector2(v1.X + dc / 2, v1.Y);

                //侧视图
                Vector2 v27 = new Vector2(v1.X + d, v1.Y + d / 2);
                Vector2 v28 = new Vector2(v27.X, v27.Y - d);
                Vector2 v29 = new Vector2(v28.X + oal, v28.Y);
                Vector2 v30 = new Vector2(v29.X, v27.Y);
                Vector2 a7 = new Vector2(v27.X - 2, v1.Y);
                Vector2 a8 = new Vector2(v29.X + 2, v1.Y);
                Vector2 a9 = new Vector2(v27.X + oal / 2, v1.Y + d / 2 + 2);
                Vector2 a10 = new Vector2(v27.X + oal / 2, v1.Y - d / 2 - 2);

                //六边形
                Vector2 a13 = new Vector2(v1.X, v1.Y + d / 2 / Math.Cos(30 * pi / 180));
                Vector2 a14 = fun.rotatePoint_Changed(v1, a13, -60);
                Vector2 a15 = fun.rotatePoint_Changed(v1, a14, -60);
                Vector2 a16 = fun.rotatePoint_Changed(v1, a15, -60);
                Vector2 a17 = fun.rotatePoint_Changed(v1, a16, -60);
                Vector2 a18 = fun.rotatePoint_Changed(v1, a17, -60);


                fun.drawcircle(dxf, v1, d / 2, 0.1, contour);

                Arc arc1 = fun.DrawArc(v3, v4, v2);
                fun.drawBArc(dxf, arc1, 0.1, contour);

                Arc arc2 = fun.DrawArc(v8, v9, v7);
                fun.drawBArc(dxf, arc2, 0.1, contour);

                Arc arc3 = fun.DrawArc(v11, v12, v10);
                fun.drawBArc(dxf, arc3, 0.1, contour);

                Arc arc4 = fun.DrawArc(v14, v15, v13);
                fun.drawBArc(dxf, arc4, 0.1, contour);

                Arc arc5 = fun.DrawArc(v17, v18, v16);
                fun.drawBArc(dxf, arc5, 0.1, contour);

                Arc arc6 = fun.DrawArc(v7, v1, v3);
                fun.drawBArc(dxf, arc6, 0.1, contour);

                Arc arc7 = fun.DrawArc(v10, v1, v8);
                fun.drawBArc(dxf, arc7, 0.1, contour);

                Arc arc8 = fun.DrawArc(v13, v1, v11);
                fun.drawBArc(dxf, arc8, 0.1, contour);

                Arc arc9 = fun.DrawArc(v16, v1, v14);
                fun.drawBArc(dxf, arc9, 0.1, contour);

                Arc arc10 = fun.DrawArc(v2, v1, v17);
                fun.drawBArc(dxf, arc10, 0.1, contour);

                Arc arc11 = fun.DrawArc(v19, v1, v6);
                fun.drawBArc(dxf, arc11, 0.1, contour);

                Arc arc12 = fun.DrawArc(v21, v1, v20);
                fun.drawBArc(dxf, arc12, 0.1, contour);

                Arc arc13 = fun.DrawArc(v23, v1, v22);
                fun.drawBArc(dxf, arc13, 0.1, contour);

                Arc arc14 = fun.DrawArc(v25, v1, v24);
                fun.drawBArc(dxf, arc14, 0.1, contour);

                Arc arc15 = fun.DrawArc(v5, v1, v26);
                fun.drawBArc(dxf, arc15, 0.1, contour);


                LwPolyline line1 = new LwPolyline();
                line1.Vertexes.Add(new LwPolylineVertex(v27));
                line1.Vertexes.Add(new LwPolylineVertex(v28));
                line1.Vertexes.Add(new LwPolylineVertex(v29));
                line1.Vertexes.Add(new LwPolylineVertex(v30));
                line1.Vertexes.Add(new LwPolylineVertex(v27));
                fun.PolyFill(dxf, line1, 0.1, contour);

                Line line2 = new Line(a3, a4);
                line2.Layer = centre;
                line2.Linetype = Linetype.DashDot;
                line2.LinetypeScale = 3;
                dxf.AddEntity(line2);

                Line line3 = new Line(a5, a6);
                line3.Layer = centre;
                line3.Linetype = Linetype.DashDot;
                line3.LinetypeScale = 3;
                dxf.AddEntity(line3);

                Line line4 = new Line(a7, a8);
                line4.Layer = centre;
                line4.Linetype = Linetype.DashDot;
                line4.LinetypeScale = 3;
                dxf.AddEntity(line4);

                Line line5 = new Line(a9, a10);
                line5.Layer = centre;
                line5.Linetype = Linetype.DashDot;
                line5.LinetypeScale = 3;
                dxf.AddEntity(line5);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                line6.Vertexes.Add(new LwPolylineVertex(a14));
                line6.Vertexes.Add(new LwPolylineVertex(a15));
                line6.Vertexes.Add(new LwPolylineVertex(a16));
                line6.Vertexes.Add(new LwPolylineVertex(a17));
                line6.Vertexes.Add(new LwPolylineVertex(a18));
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                fun.PolyFill(dxf, line6, 0.1, contour);


                //标注

                double height = 2;
                double arrowsize = 2;
                double exline = 2;


                fun.dimrot1(dxf, a1, a2, 0, d / 2 + d / 4, 1, height, arrowsize, exline, "D=" + d, "", "");

                fun.dimrot1(dxf, v27, v30, 0, d / 4, 1, height, arrowsize, exline, "T=" + oal, "", "");

                fun.dimrot1(dxf, a11, a12, 180, d / 2 + d / 4, 1, height, arrowsize, exline, "TD=" + dc, "", "");



            }



            if (hand.Equals("6"))
            {

                double g = 6;

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = fun.Polar(v1, (90 + 90 / g) * pi / 180, dc / 2);
                Vector2 v3 = fun.Polar(v1, (90 - 90 / g) * pi / 180, dc / 2);
                Vector2 v4 = new Vector2(v1.X, v1.Y + dc / 2 + ((d - 5.4) / 2 - dc / 2) / 5.5);
                Vector2 v5 = fun.rotatePoint_Changed(v4, v2, -20);
                Vector2 v6 = fun.rotatePoint_Changed(v4, v3, 20);
                Vector2 v7 = fun.rotatePoint_Changed(v1, v2, -60);
                Vector2 v8 = fun.rotatePoint_Changed(v1, v3, -60);
                Vector2 v9 = fun.rotatePoint_Changed(v1, v4, -60);
                Vector2 v10 = fun.rotatePoint_Changed(v1, v7, -60);
                Vector2 v11 = fun.rotatePoint_Changed(v1, v8, -60);
                Vector2 v12 = fun.rotatePoint_Changed(v1, v9, -60);
                Vector2 v13 = fun.rotatePoint_Changed(v1, v10, -60);
                Vector2 v14 = fun.rotatePoint_Changed(v1, v11, -60);
                Vector2 v15 = fun.rotatePoint_Changed(v1, v12, -60);
                Vector2 v16 = fun.rotatePoint_Changed(v1, v13, -60);
                Vector2 v17 = fun.rotatePoint_Changed(v1, v14, -60);
                Vector2 v18 = fun.rotatePoint_Changed(v1, v15, -60);
                Vector2 v19 = fun.rotatePoint_Changed(v1, v16, -60);
                Vector2 v20 = fun.rotatePoint_Changed(v1, v17, -60);
                Vector2 v21 = fun.rotatePoint_Changed(v1, v18, -60);
                Vector2 v22 = fun.rotatePoint_Changed(v1, v5, -60);
                Vector2 v23 = fun.rotatePoint_Changed(v1, v6, -60);
                Vector2 v24 = fun.rotatePoint_Changed(v1, v22, -60);
                Vector2 v25 = fun.rotatePoint_Changed(v1, v23, -60);
                Vector2 v26 = fun.rotatePoint_Changed(v1, v24, -60);
                Vector2 v27 = fun.rotatePoint_Changed(v1, v25, -60);
                Vector2 v28 = fun.rotatePoint_Changed(v1, v26, -60);
                Vector2 v29 = fun.rotatePoint_Changed(v1, v27, -60);
                Vector2 v30 = fun.rotatePoint_Changed(v1, v28, -60);
                Vector2 v31 = fun.rotatePoint_Changed(v1, v29, -60);
                Vector2 a1 = new Vector2(v1.X - d / 2, v1.Y);
                Vector2 a2 = new Vector2(v1.X + d / 2, v1.Y);
                Vector2 a3 = new Vector2(v1.X - d / 2 - 2, v1.Y);
                Vector2 a4 = new Vector2(v1.X + d / 2 + 2, v1.Y);
                Vector2 a5 = new Vector2(v1.X, v1.Y + d / 2 + 2);
                Vector2 a6 = new Vector2(v1.X, v1.Y - d / 2 - 2);
                Vector2 a11 = new Vector2(v1.X - dc / 2, v1.Y);
                Vector2 a12 = new Vector2(v1.X + dc / 2, v1.Y);

                //侧视图
                Vector2 v32 = new Vector2(v1.X + d, v1.Y + d / 2);
                Vector2 v33 = new Vector2(v32.X, v32.Y - d);
                Vector2 v34 = new Vector2(v33.X + oal, v33.Y);
                Vector2 v35 = new Vector2(v34.X, v32.Y);
                Vector2 a7 = new Vector2(v32.X - 2, v1.Y);
                Vector2 a8 = new Vector2(v34.X + 2, v1.Y);
                Vector2 a9 = new Vector2(v32.X + oal / 2, v1.Y + d / 2 + 2);
                Vector2 a10 = new Vector2(v32.X + oal / 2, v1.Y - d / 2 - 2);

                //六边形
                Vector2 a13 = new Vector2(v1.X, v1.Y + d / 2 / Math.Cos(30 * pi / 180));
                Vector2 a14 = fun.rotatePoint_Changed(v1, a13, -60);
                Vector2 a15 = fun.rotatePoint_Changed(v1, a14, -60);
                Vector2 a16 = fun.rotatePoint_Changed(v1, a15, -60);
                Vector2 a17 = fun.rotatePoint_Changed(v1, a16, -60);
                Vector2 a18 = fun.rotatePoint_Changed(v1, a17, -60);




                fun.drawcircle(dxf, v1, d / 2, 0.1, contour);

                Arc arc1 = fun.DrawArc(v3, v4, v2);
                fun.drawBArc(dxf, arc1, 0.1, contour);

                Arc arc2 = fun.DrawArc(v8, v9, v7);
                fun.drawBArc(dxf, arc2, 0.1, contour);

                Arc arc3 = fun.DrawArc(v11, v12, v10);
                fun.drawBArc(dxf, arc3, 0.1, contour);

                Arc arc4 = fun.DrawArc(v14, v15, v13);
                fun.drawBArc(dxf, arc4, 0.1, contour);

                Arc arc5 = fun.DrawArc(v17, v18, v16);
                fun.drawBArc(dxf, arc5, 0.1, contour);

                Arc arc6 = fun.DrawArc(v20, v21, v19);
                fun.drawBArc(dxf, arc6, 0.1, contour);

                Arc arc7 = fun.DrawArc(v7, v1, v3);
                fun.drawBArc(dxf, arc7, 0.1, contour);

                Arc arc8 = fun.DrawArc(v10, v1, v8);
                fun.drawBArc(dxf, arc8, 0.1, contour);

                Arc arc9 = fun.DrawArc(v13, v1, v11);
                fun.drawBArc(dxf, arc9, 0.1, contour);

                Arc arc10 = fun.DrawArc(v16, v1, v14);
                fun.drawBArc(dxf, arc10, 0.1, contour);

                Arc arc11 = fun.DrawArc(v19, v1, v17);
                fun.drawBArc(dxf, arc11, 0.1, contour);

                Arc arc12 = fun.DrawArc(v2, v1, v20);
                fun.drawBArc(dxf, arc12, 0.1, contour);

                Arc arc13 = fun.DrawArc(v22, v1, v6);
                fun.drawBArc(dxf, arc13, 0.1, contour);

                Arc arc14 = fun.DrawArc(v24, v1, v23);
                fun.drawBArc(dxf, arc14, 0.1, contour);

                Arc arc15 = fun.DrawArc(v26, v1, v25);
                fun.drawBArc(dxf, arc15, 0.1, contour);

                Arc arc16 = fun.DrawArc(v28, v1, v27);
                fun.drawBArc(dxf, arc16, 0.1, contour);

                Arc arc17 = fun.DrawArc(v30, v1, v29);
                fun.drawBArc(dxf, arc17, 0.1, contour);

                Arc arc18 = fun.DrawArc(v5, v1, v31);
                fun.drawBArc(dxf, arc18, 0.1, contour);


                LwPolyline line1 = new LwPolyline();
                line1.Vertexes.Add(new LwPolylineVertex(v32));
                line1.Vertexes.Add(new LwPolylineVertex(v33));
                line1.Vertexes.Add(new LwPolylineVertex(v34));
                line1.Vertexes.Add(new LwPolylineVertex(v35));
                line1.Vertexes.Add(new LwPolylineVertex(v32));
                fun.PolyFill(dxf, line1, 0.1, contour);

                Line line2 = new Line(a3, a4);
                line2.Layer = centre;
                line2.Linetype = Linetype.DashDot;
                line2.LinetypeScale = 3;
                dxf.AddEntity(line2);

                Line line3 = new Line(a5, a6);
                line3.Layer = centre;
                line3.Linetype = Linetype.DashDot;
                line3.LinetypeScale = 3;
                dxf.AddEntity(line3);

                Line line4 = new Line(a7, a8);
                line4.Layer = centre;
                line4.Linetype = Linetype.DashDot;
                line4.LinetypeScale = 3;
                dxf.AddEntity(line4);

                Line line5 = new Line(a9, a10);
                line5.Layer = centre;
                line5.Linetype = Linetype.DashDot;
                line5.LinetypeScale = 3;
                dxf.AddEntity(line5);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                line6.Vertexes.Add(new LwPolylineVertex(a14));
                line6.Vertexes.Add(new LwPolylineVertex(a15));
                line6.Vertexes.Add(new LwPolylineVertex(a16));
                line6.Vertexes.Add(new LwPolylineVertex(a17));
                line6.Vertexes.Add(new LwPolylineVertex(a18));
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                fun.PolyFill(dxf, line6, 0.1, contour);

                //标注


                double height = 2;
                double arrowsize = 2;
                double exline = 2;


                fun.dimrot1(dxf, a1, a2, 0, d / 2 + d / 4, 1, height, arrowsize, exline, "D=" + d, "", "");

                fun.dimrot1(dxf, v32, v35, 0, d / 4, 1, height, arrowsize, exline, "T=" + oal, "", "");

                fun.dimrot1(dxf, a11, a12, 180, d / 2 + d / 4, 1, height, arrowsize, exline, "TD=" + dc, "", "");


            }

            if (hand.Equals("8"))
            {
                double g = 8;

                Vector2 v1 = new Vector2(0, 0);
                Vector2 v2 = fun.Polar(v1, (90 + 90 / g) * pi / 180, dc / 2);
                Vector2 v3 = fun.Polar(v1, (90 - 90 / g) * pi / 180, dc / 2);
                Vector2 v4 = new Vector2(v1.X, v1.Y + dc / 2 + ((d - 5.4) / 2 - dc / 2) / 7);
                Vector2 v5 = fun.rotatePoint_Changed(v4, v2, -20);
                Vector2 v6 = fun.rotatePoint_Changed(v4, v3, 20);
                Vector2 v7 = fun.rotatePoint_Changed(v1, v2, -45);
                Vector2 v8 = fun.rotatePoint_Changed(v1, v3, -45);
                Vector2 v9 = fun.rotatePoint_Changed(v1, v4, -45);
                Vector2 v10 = fun.rotatePoint_Changed(v1, v7, -45);
                Vector2 v11 = fun.rotatePoint_Changed(v1, v8, -45);
                Vector2 v12 = fun.rotatePoint_Changed(v1, v9, -45);
                Vector2 v13 = fun.rotatePoint_Changed(v1, v10, -45);
                Vector2 v14 = fun.rotatePoint_Changed(v1, v11, -45);
                Vector2 v15 = fun.rotatePoint_Changed(v1, v12, -45);
                Vector2 v16 = fun.rotatePoint_Changed(v1, v13, -45);
                Vector2 v17 = fun.rotatePoint_Changed(v1, v14, -45);
                Vector2 v18 = fun.rotatePoint_Changed(v1, v15, -45);
                Vector2 v19 = fun.rotatePoint_Changed(v1, v16, -45);
                Vector2 v20 = fun.rotatePoint_Changed(v1, v17, -45);
                Vector2 v21 = fun.rotatePoint_Changed(v1, v18, -45);
                Vector2 v22 = fun.rotatePoint_Changed(v1, v19, -45);
                Vector2 v23 = fun.rotatePoint_Changed(v1, v20, -45);
                Vector2 v24 = fun.rotatePoint_Changed(v1, v21, -45);
                Vector2 v25 = fun.rotatePoint_Changed(v1, v22, -45);
                Vector2 v26 = fun.rotatePoint_Changed(v1, v23, -45);
                Vector2 v27 = fun.rotatePoint_Changed(v1, v24, -45);
                Vector2 v28 = fun.rotatePoint_Changed(v1, v5, -45);
                Vector2 v29 = fun.rotatePoint_Changed(v1, v6, -45);
                Vector2 v30 = fun.rotatePoint_Changed(v1, v28, -45);
                Vector2 v31 = fun.rotatePoint_Changed(v1, v29, -45);
                Vector2 v32 = fun.rotatePoint_Changed(v1, v30, -45);
                Vector2 v33 = fun.rotatePoint_Changed(v1, v31, -45);
                Vector2 v34 = fun.rotatePoint_Changed(v1, v32, -45);
                Vector2 v35 = fun.rotatePoint_Changed(v1, v33, -45);
                Vector2 v36 = fun.rotatePoint_Changed(v1, v34, -45);
                Vector2 v37 = fun.rotatePoint_Changed(v1, v35, -45);
                Vector2 v38 = fun.rotatePoint_Changed(v1, v36, -45);
                Vector2 v39 = fun.rotatePoint_Changed(v1, v37, -45);
                Vector2 v40 = fun.rotatePoint_Changed(v1, v38, -45);
                Vector2 v41 = fun.rotatePoint_Changed(v1, v39, -45);
                Vector2 v42 = fun.rotatePoint_Changed(v1, v40, -45);
                Vector2 v43 = fun.rotatePoint_Changed(v1, v41, -45);
                Vector2 a1 = new Vector2(v1.X - d / 2, v1.Y);
                Vector2 a2 = new Vector2(v1.X + d / 2, v1.Y);
                Vector2 a3 = new Vector2(v1.X - d / 2 - 2, v1.Y);
                Vector2 a4 = new Vector2(v1.X + d / 2 + 2, v1.Y);
                Vector2 a5 = new Vector2(v1.X, v1.Y + d / 2 + 2);
                Vector2 a6 = new Vector2(v1.X, v1.Y - d / 2 - 2);
                Vector2 a11 = new Vector2(v1.X - dc / 2, v1.Y);
                Vector2 a12 = new Vector2(v1.X + dc / 2, v1.Y);

                //侧视图
                Vector2 v44 = new Vector2(v1.X + d, v1.Y + d / 2);
                Vector2 v45 = new Vector2(v44.X, v44.Y - d);
                Vector2 v46 = new Vector2(v45.X + oal, v45.Y);
                Vector2 v47 = new Vector2(v46.X, v44.Y);
                Vector2 a7 = new Vector2(v44.X - 2, v1.Y);
                Vector2 a8 = new Vector2(v46.X + 2, v1.Y);
                Vector2 a9 = new Vector2(v44.X + oal / 2, v1.Y + d / 2 + 2);
                Vector2 a10 = new Vector2(v44.X + oal / 2, v1.Y - d / 2 - 2);

                //六边形
                Vector2 a13 = new Vector2(v1.X, v1.Y + d / 2 / Math.Cos(30 * pi / 180));
                Vector2 a14 = fun.rotatePoint_Changed(v1, a13, -60);
                Vector2 a15 = fun.rotatePoint_Changed(v1, a14, -60);
                Vector2 a16 = fun.rotatePoint_Changed(v1, a15, -60);
                Vector2 a17 = fun.rotatePoint_Changed(v1, a16, -60);
                Vector2 a18 = fun.rotatePoint_Changed(v1, a17, -60);




                fun.drawcircle(dxf, v1, d / 2, 0.1, contour);

                Arc arc1 = fun.DrawArc(v3, v4, v2);
                fun.drawBArc(dxf, arc1, 0.1, contour);

                Arc arc2 = fun.DrawArc(v8, v9, v7);
                fun.drawBArc(dxf, arc2, 0.1, contour);

                Arc arc3 = fun.DrawArc(v11, v12, v10);
                fun.drawBArc(dxf, arc3, 0.1, contour);

                Arc arc4 = fun.DrawArc(v14, v15, v13);
                fun.drawBArc(dxf, arc4, 0.1, contour);

                Arc arc5 = fun.DrawArc(v17, v18, v16);
                fun.drawBArc(dxf, arc5, 0.1, contour);

                Arc arc6 = fun.DrawArc(v20, v21, v19);
                fun.drawBArc(dxf, arc6, 0.1, contour);

                Arc arc7 = fun.DrawArc(v23, v24, v22);
                fun.drawBArc(dxf, arc7, 0.1, contour);

                Arc arc8 = fun.DrawArc(v26, v27, v25);
                fun.drawBArc(dxf, arc8, 0.1, contour);

                Arc arc9 = fun.DrawArc(v7, v1, v3);
                fun.drawBArc(dxf, arc9, 0.1, contour);

                Arc arc10 = fun.DrawArc(v10, v1, v8);
                fun.drawBArc(dxf, arc10, 0.1, contour);

                Arc arc11 = fun.DrawArc(v13, v1, v11);
                fun.drawBArc(dxf, arc11, 0.1, contour);

                Arc arc12 = fun.DrawArc(v16, v1, v14);
                fun.drawBArc(dxf, arc12, 0.1, contour);

                Arc arc13 = fun.DrawArc(v19, v1, v17);
                fun.drawBArc(dxf, arc13, 0.1, contour);

                Arc arc14 = fun.DrawArc(v22, v1, v20);
                fun.drawBArc(dxf, arc14, 0.1, contour);

                Arc arc15 = fun.DrawArc(v25, v1, v23);
                fun.drawBArc(dxf, arc15, 0.1, contour);

                Arc arc16 = fun.DrawArc(v2, v1, v26);
                fun.drawBArc(dxf, arc16, 0.1, contour);

                Arc arc17 = fun.DrawArc(v28, v1, v6);
                fun.drawBArc(dxf, arc17, 0.1, contour);

                Arc arc18 = fun.DrawArc(v30, v1, v29);
                fun.drawBArc(dxf, arc18, 0.1, contour);

                Arc arc19 = fun.DrawArc(v32, v1, v31);
                fun.drawBArc(dxf, arc19, 0.1, contour);

                Arc arc20 = fun.DrawArc(v34, v1, v33);
                fun.drawBArc(dxf, arc20, 0.1, contour);

                Arc arc21 = fun.DrawArc(v36, v1, v35);
                fun.drawBArc(dxf, arc21, 0.1, contour);

                Arc arc22 = fun.DrawArc(v38, v1, v37);
                fun.drawBArc(dxf, arc22, 0.1, contour);

                Arc arc23 = fun.DrawArc(v40, v1, v39);
                fun.drawBArc(dxf, arc23, 0.1, contour);

                Arc arc24 = fun.DrawArc(v5, v1, v41);
                fun.drawBArc(dxf, arc24, 0.1, contour);

                LwPolyline line1 = new LwPolyline();
                line1.Vertexes.Add(new LwPolylineVertex(v44));
                line1.Vertexes.Add(new LwPolylineVertex(v45));
                line1.Vertexes.Add(new LwPolylineVertex(v46));
                line1.Vertexes.Add(new LwPolylineVertex(v47));
                line1.Vertexes.Add(new LwPolylineVertex(v44));
                fun.PolyFill(dxf, line1, 0.1, contour);

                Line line2 = new Line(a3, a4);
                line2.Layer = centre;
                line2.Linetype = Linetype.DashDot;
                line2.LinetypeScale = 3;
                dxf.AddEntity(line2);

                Line line3 = new Line(a5, a6);
                line3.Layer = centre;
                line3.Linetype = Linetype.DashDot;
                line3.LinetypeScale = 3;
                dxf.AddEntity(line3);

                Line line4 = new Line(a7, a8);
                line4.Layer = centre;
                line4.Linetype = Linetype.DashDot;
                line4.LinetypeScale = 3;
                dxf.AddEntity(line4);

                Line line5 = new Line(a9, a10);
                line5.Layer = centre;
                line5.Linetype = Linetype.DashDot;
                line5.LinetypeScale = 3;
                dxf.AddEntity(line5);

                LwPolyline line6 = new LwPolyline();
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                line6.Vertexes.Add(new LwPolylineVertex(a14));
                line6.Vertexes.Add(new LwPolylineVertex(a15));
                line6.Vertexes.Add(new LwPolylineVertex(a16));
                line6.Vertexes.Add(new LwPolylineVertex(a17));
                line6.Vertexes.Add(new LwPolylineVertex(a18));
                line6.Vertexes.Add(new LwPolylineVertex(a13));
                fun.PolyFill(dxf, line6, 0.1, contour);


                //标注

                double height = 2;
                double arrowsize = 2;
                double exline = 2;


                fun.dimrot1(dxf, a1, a2, 0, d / 2 + d / 4, 1, height, arrowsize, exline, "D=" + d, "", "");

                fun.dimrot1(dxf, v44, v47, 0, d / 4, 1, height, arrowsize, exline, "T=" + oal, "", "");

                fun.dimrot1(dxf, a11, a12, 180, d / 2 + d / 4, 1, height, arrowsize, exline, "TD=" + dc, "", "");


            }

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            //定义格式，路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);


        }

    }
}